package com.pb.infra.oth.util;

import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;

/**
 * @author:廖昊源
 * @create: 2023-04-03 15:58
 * @Description: obj工具类
 */
public class ObjectUtli {
    /**
     * 判断对象是否为空
     * @param value
     * @return boolean
     */
    public static boolean isEmpty(Object value) {
        if (value == null) {
            return true;
        }
        if ((value instanceof StringBuffer) && (((StringBuffer) value).length() <= 0 || ((StringBuffer) value).toString().trim().equalsIgnoreCase("null"))) {
            return true;
        }
        //qiuzhi新增一条
        if ((value instanceof StringBuilder) && (((StringBuilder) value).length() <= 0 || ((StringBuilder) value).toString().trim().equalsIgnoreCase("null"))) {
            return true;
        }
        if ((value instanceof String) && (((String) value).trim().length() <= 0 || ((String) value).trim().equalsIgnoreCase("null") || ((String) value).trim().equalsIgnoreCase("undefined"))) {
            return true;
        }
        if ((value instanceof Object[]) && (((Object[]) value).length <= 0)) {
            return true;
        }
        if ((value instanceof Collection<?>) && ((Collection<?>) value).size() <= 0) {
            return true;
        }
        if ((value instanceof Dictionary<?, ?>) && ((Dictionary<?, ?>) value).size() <= 0) {
            return true;
        }
        if ((value instanceof HashMap<?, ?>) && (((HashMap<?, ?>) value).size() <= 0)) {
            return true;
        }
        return false;
    }


}
